package com.newcapec.lesson1;

import java.util.Objects;

public class Teacher extends Person{
    private String subject;

    public Teacher() {
    }

    public Teacher(String name, String sex, int age, String subject) {
        super(name, sex, age);
        this.subject = subject;
    }

    public Teacher(Teacher teacher){
/*        this.setName(teacher.getName());
        this.setAge(teacher.getAge());
        this.setSex(teacher.getSex());*/
        super(teacher);
        this.subject = teacher.subject;
    }

    @Override
    public boolean equals(Object o) {
        // == 比较的是字面量
        if (this == o) {
            return true;
        }
        //此时地址不一样，需要查看内容是否一致
        if (o instanceof Teacher) {
            //判断具体内容
            Teacher teacher = (Teacher) o;
            if(super.equals(teacher) &&
                    this.getSubject() == teacher.getSubject()){
                return true;
            }
        }

        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(subject);
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    @Override
    public String toString() {
        return "Teacher{" +super.toString()+
                "subject='" + subject + '\'' +
                '}';
    }
}
